<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="../../set.jsp" />
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>编辑平台</title>
<jsp:include page="../../cite.jsp" />
<link rel="stylesheet" href="${_path}/theme/theme-menu.css">
<script src="${_path}/lib/bootbox-4.4.0/bootbox.min.js"></script>
<script src="${_path}/lib/ueditor-1.4.3.1/ueditor.config.js"></script>
<script src="${_path}/lib/ueditor-1.4.3.1/ueditor.all.min.js"></script>
<style>
.body {
	padding-top: 20px;
}

.body .panel {
	width: 700px;
	margin: 0 auto;
}

.body .panel>.panel-heading {
	padding: 0;
}

.body .panel>.panel-heading>.breadcrumb {
	margin-bottom: 0;
}

.body .panel>.panel-body {
	padding: 20px;
}

.body .btns {
	margin-top: 30px;
}
</style>
</head>
<body>
	<jsp:include page="../../header.jsp" />
	<jsp:include page="./compile-menu.jsp?active=messages" />
	<div class="body">
		<div class="panel panel-default">
			<div class="panel-heading">
				<ol class="breadcrumb">
					<li>
						<a href="../">消息</a>
					</li>
					<li class="active">新增</li>
				</ol>
			</div>
			<div class="panel-body">
				<form id="form">
					<div class="form-group">
						<label for="title">
							<span class="text-danger">*</span>
							标题：
						</label>
						<input class="form-control input-sm" name="title" placeholder="标题" autofocus required>
					</div>
					<div class="form-group">
						<label>
							<span class="text-danger">*</span>
							正文：
						</label>
						<script class="editor" id="editor" style="height: 250px;"></script>
					</div>
					<div class="form-group btns">
						<a href="../" class="btn btn-default btn-sm">返 回</a>
						<a href="./" class="btn btn-warning btn-sm">重 置</a>
						<button class="btn btn-primary btn-sm" data-loading-text="提交中...">添 加</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<script>
		$(function() {
			bootbox.setLocale('zh_CN');
			var ue = UE.getEditor('editor');
			$('#form').submit(function() {
				submitClick();
				return false;
			});
			function submitClick() {
				$('#form button[data-loading-text]').button('loading');
				$.ajax({
					url : './',
					type : 'post',
					dataType : 'json',
					data : {
						title : $('#form input[name=title]').val(),
						content : ue.getContent()
					},
					success : function(result) {
						if (result.succ == 0)
							bootbox.confirm('保存成功。是否继续添加？', function(c) {
								if (c)
									location.reload();
								else
									location.href = '../';
							});
						else {
							bootbox.alert(result.message);
							$('#form button[data-loading-text]').button('reset');
						}
					},
					error : function() {
						bootbox.alert('网络连接失败');
						$('#form button[data-loading-text]').button('reset');
						console.log('新增消息失败');
					}
				});
			}
		});
	</script>
</body>
</html>